package cn.wl.gulimall.order.service.impl;

import cn.wl.gulimall.order.entity.OrderEntity;
import cn.wl.gulimall.order.entity.OrderReturnReasonEntity;
import com.rabbitmq.client.Channel;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

import java.io.IOException;
import java.util.Map;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.wl.common.utils.PageUtils;
import cn.wl.common.utils.Query;

import cn.wl.gulimall.order.dao.OrderItemDao;
import cn.wl.gulimall.order.entity.OrderItemEntity;
import cn.wl.gulimall.order.service.OrderItemService;

@RabbitListener(queues = {"hello-java-queue"})
@Service("orderItemService")
public class OrderItemServiceImpl extends ServiceImpl<OrderItemDao, OrderItemEntity> implements OrderItemService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        IPage<OrderItemEntity> page = this.page(
                new Query<OrderItemEntity>().getPage(params),
                new QueryWrapper<OrderItemEntity>()
        );
        return new PageUtils(page);
    }

    //queues：声明需要监听的所有队列
    @RabbitHandler
    public void recieveMessage(Message msg, OrderReturnReasonEntity content, Channel channel){
        //channel内按顺序自增的
        long deliveryTag = msg.getMessageProperties().getDeliveryTag();
        System.out.println("接收到消息===>111内容:"+content);
        //签收获取,非批量模式
        try {
            channel.basicAck(deliveryTag,false);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }

    @RabbitHandler
    public void recieveMessage2(OrderEntity content, Channel channel){
        System.out.println("接收到消息-===>222内容:"+content);
    }

}